<?php

class PortalController extends Site_Controller_Action
{
    public function init()
    {
        
    } 

    public function indexAction()
    {       
        //$obj = new Sistema_Model_DbTable_Catsegmento();
        //$where = ' CTS_STA = 1';
        //$result = $obj->fetchAll($obj->select()->where($where)->order('CTS_ORD ASC'));
        
        $result = $this->db->fetchAll('SELECT SQL_CACHE * FROM CATSEGMENTO WHERE CTS_STA = 1 ORDER BY CTS_ORD ASC');
        
        $this->view->result = $result;
        
        $this->_helper->layout->setLayout("layout_portal");
    }
    public function escolheAction()
    {
        $this->_helper->layout->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender();
        
        $sessao = new Zend_Session_Namespace('segmento');
        
        $CTS_ID = $this->_getParam('id', 1);
        
        //$seg = New Sistema_Model_DbTable_Catsegmento();
        //$seq = $seg->fetchRow('CTS_ID = '.$CTS_ID)->toArray();
        $seq = $this->db->fetchRow('SELECT SQL_CACHE * FROM CATSEGMENTO WHERE CTS_ID = '.$CTS_ID);
        
        $sessao->CTS_ID = $CTS_ID; 
        $sessao->CTS_NOM = $seq['CTS_NOM']; 
        $sessao->CTS_END = $seq['CTS_END']; 
        $sessao->CTS_TEL = $seq['CTS_TEL'];
        $sessao->CTS_FAC = $seq['CTS_FAC'];
        
        $img = glob('public/upload/catsegmento/'.$sessao->CTS_ID.'_rp.*');

        if(isset($img[0]))  $sessao->img_rp = $img[0];  
        
        $this->_helper->redirector('index','index');
    }

}

